<html>
<head><meta charset="utf-8"><title>Chalk hang · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html">Chalk hang</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="174799507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/174799507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#174799507">(Sep 03 2019 at 15:28)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> <span class="user-mention" data-user-id="133169">@matklad</span> I've hacked together some code to print the stuff we're passing to Chalk (<a href="https://github.com/flodiebold/rust-analyzer/commits/chalk-reproduce" target="_blank" title="https://github.com/flodiebold/rust-analyzer/commits/chalk-reproduce">here</a>), and here's the beginning of the output for the actix-web hang: <a href="https://gist.github.com/flodiebold/529ec845c39b5cb81909aac4b613ba44" target="_blank" title="https://gist.github.com/flodiebold/529ec845c39b5cb81909aac4b613ba44">gist</a></p>
<p>you can see it's starting with the goal <code>Implements(?0: ServiceFactory&lt;TcpStream&gt;)</code>, and then enumerating kind of the whole world because the first where clause of the impl never applies (but it starts with the last). Although it seems like this would be problematic even if there was some solution for the first where clause.</p>
<p>The thing is, we wouldn't even need to solve this: Even if it had a unique solution, rustc wouldn't infer that. So are we missing some short-circuit behavior here? (OTOH it seems that even if RA somehow avoided trying to solve this goal, it could easily happen while solving some other goal...)</p>



<a name="174830900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/174830900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#174830900">(Sep 03 2019 at 21:25)</a>:</h4>
<p>it's true that rustc doesn't solve these sorts of cases, though I would like it to (I think...)</p>



<a name="174928399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/174928399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#174928399">(Sep 04 2019 at 22:24)</a>:</h4>
<p>ok, i'm circling back to this</p>



<a name="174928459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/174928459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#174928459">(Sep 04 2019 at 22:25)</a>:</h4>
<p>it looks like it's trying to solve the <code>T: NewService</code>, I guess this is what you meant?</p>



<a name="174949501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/174949501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#174949501">(Sep 05 2019 at 06:55)</a>:</h4>
<p>yeah</p>



<a name="175100451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175100451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175100451">(Sep 06 2019 at 20:25)</a>:</h4>
<p>Someone posted another example <a href="https://github.com/rust-analyzer/rust-analyzer/issues/1744#issuecomment-528826370" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/issues/1744#issuecomment-528826370">here</a>. The <a href="https://gist.github.com/flodiebold/3aa625b711ca6984150574f57e7c58c8" target="_blank" title="https://gist.github.com/flodiebold/3aa625b711ca6984150574f57e7c58c8">output</a> shows it's trying to enumerate <code>Copy</code> and <code>Ord</code> types, which there aren't actually many because we don't handle derives yet and don't manage to expand the macros in the standard library enough to get the impls for the primitive types, but there are enough impls to make it search a long time...</p>



<a name="175147088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175147088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175147088">(Sep 07 2019 at 16:39)</a>:</h4>
<p>it seems to me this should be fixable with a smarter selection of the next subgoal, i.e. <a href="https://github.com/rust-lang/chalk/issues/80" target="_blank" title="https://github.com/rust-lang/chalk/issues/80">chalk#80</a>. It would have to be smart enough to select a good clause when it sees <code>I: Bounded, I: Zero, I: DivAssign&lt;Self&gt;, I: Ord, I: Copy</code> though, so maybe it would need to check how many impls there are for each of these... or maybe it could even try another subgoal if it takes too long one the current one? <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="175149079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175149079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175149079">(Sep 07 2019 at 17:43)</a>:</h4>
<p>the last thing would be a kind of 'fuel for subgoals', actually <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="175186517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175186517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175186517">(Sep 08 2019 at 14:24)</a>:</h4>
<p>I'm now running into another problem with <code>?0: Trait</code> goals: I'm giving types to closures; each closure gets its own type, and that type should implement the <code>Fn</code> traits. But what I then do when Chalk asks for impls for <code>Fn</code>? I would have to iterate all bodies in the whole crate to list all closures, because the solver is shared for the whole crate. (I could maybe make the solver per-def, but that doesn't seem like a good idea...)</p>
<p>Now Chalk could of course pass a hint about the self type (I tried that), but actually at first it doesn't know the self type (it's trying to solve <code>?0: Fn</code>), and if I don't return the impl in that call I think it caches that and doesn't try again later with a more specific type. So it seems to me I would need some kind of way of saying <code>?0: Fn</code> is always ambiguous, and we should only try to solve it when we have more information...</p>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> what do you think would be the 'correct' approach for this?</p>



<a name="175265349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175265349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175265349">(Sep 09 2019 at 17:46)</a>:</h4>
<p>Hey <span class="user-mention" data-user-id="129457">@Florian Diebold</span> -- let me read in detail your posts -- but I was giving this some thought over the weekend. </p>
<p>Overall, this was the sort of scenario that I had hoped to use the "non-enumerable" concept to control.</p>
<p>To start, we could certainly say that a goal like <code>?T: Foo</code> for <em>any</em> trait <code>Foo</code> is non-enumerable, much as rustc does today.</p>



<a name="175265367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175265367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175265367">(Sep 09 2019 at 17:47)</a>:</h4>
<p>I'm not wild about it, because it's an arbitrary limitation, but it might be a practical step</p>



<a name="175265383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175265383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175265383">(Sep 09 2019 at 17:47)</a>:</h4>
<p>The other obvious thing is that yes I had expected us to get smarter about controlling our selection order</p>



<a name="175265540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175265540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175265540">(Sep 09 2019 at 17:49)</a>:</h4>
<blockquote>
<p>because it's an arbitrary limitation</p>
</blockquote>
<p>I think limitations which clearly delineate the scope of the search can be good :) Like, allowing <code>pub</code> impls in function bodies would be a useful limitation.</p>



<a name="175265552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175265552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175265552">(Sep 09 2019 at 17:49)</a>:</h4>
<p>I agree, I just don't like that one</p>



<a name="175265557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175265557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175265557">(Sep 09 2019 at 17:49)</a>:</h4>
<p>but I still think it'd be good to impose it for now</p>



<a name="175265700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175265700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175265700">(Sep 09 2019 at 17:51)</a>:</h4>
<p>(My specific reason not to like that one is that it interferes with the design I would prefer for the <code>Try</code> trait, making some kinds of inference more difficult there)</p>



<a name="175265727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175265727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175265727">(Sep 09 2019 at 17:51)</a>:</h4>
<p>In any case, I think reproducing rustc's logic for now is fine, and I like that we have the means to talk more carefully about what we want the rules to be</p>



<a name="175265739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175265739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175265739">(Sep 09 2019 at 17:51)</a>:</h4>
<p>It'd be good to know if there are other problems once we take that step :)</p>



<a name="175274442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175274442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175274442">(Sep 09 2019 at 19:26)</a>:</h4>
<blockquote>
<p>To start, we could certainly say that a goal like <code>?T: Foo</code> for <em>any</em> trait <code>Foo</code> is non-enumerable, much as rustc does today.</p>
</blockquote>
<p>So I realize that we can do this -- and perhaps <em>should</em> do this -- on the rust-analyzer side. Just opened <a href="https://github.com/rust-analyzer/rust-analyzer/issues/1800" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/issues/1800">rust-analyzer#1800</a>.</p>



<a name="175274752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175274752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175274752">(Sep 09 2019 at 19:30)</a>:</h4>
<p>Will this mean Chalk will return an ambiguous result if it has to solve such a goal, or just that it'll try those goals last?</p>



<a name="175275210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175275210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175275210">(Sep 09 2019 at 19:36)</a>:</h4>
<p>ah, from reading the code, the former :)</p>



<a name="175276407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175276407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175276407">(Sep 09 2019 at 19:50)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span> well sort of both</p>



<a name="175276451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Chalk%20hang/near/175276451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Chalk.20hang.html#175276451">(Sep 09 2019 at 19:51)</a>:</h4>
<p>it will re-order such tasks last (dynamically, though, but we can improve that), but if ultimately it <em>has</em> to solve such a thing, it will return ambig</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>